window.global_sms = {
    sms:'/sms/sendSmsVerifyCode'
};


function GetDate() {
    //TODO 获取客户机日期格式为：2016-05-09
    var myDate = new Date();
    var sMonth="00"+(myDate.getMonth()+1);
    sMonth=sMonth.substr(sMonth.length-2,2);
    var sDay="00"+(myDate.getDate());
    sDay=sDay.substr(sDay.length-2,2);
    return myDate.getFullYear()+"-"+sMonth+"-"+sDay;
}


function closePage(){
    if(navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Chrome") != -1){
        window.location.href = "about:blank";
        // window.close();
    }else{
        window.location.href = "about:blank";
        window.opener = null;
        window.open("", "_self");
        // window.close();
    }
}


function mapurl(url){
    var host = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1465788a8b4adbeb&redirect_uri=http://pms.wzyskj.net' + url + '&response_type=code&scope=snsapi_base&state=200#wechat_redirect';
		return host;
	}


function SetSessionKeyVale(sKey,sValue){
        //TODO ！设置会话指定键的值！  设置session值
        var sRet='';
        $.ajax({
            type: "post",
            url: "/Manage/SetSession",
            data: {
                sKey:sKey,
                sValue:sValue
            },
            async: false,
            success: function(data) {
                sRet=data;
            }
        });
        return sRet;
    }
    
    
    
function GetSessionKeyVale(sKey){
    //TODO ！设置会话指定键的值！  设置session值
    var sRet='';
    $.ajax({
        type: "post",
        url: "/Manage/GetSession",
        data: {
            sKey:sKey,
        },
        async: false,
        success: function(data) {
            sRet=data;
        }
    });
    return sRet;
}



function getParameterByName(paramName) {
    //TODO 获取URL参数
    var args = {};
    var argsStr = location.search;  //获取URL参数字符串
    if (argsStr.length > 0) {
        argsStr = argsStr.substring(1);
        var nameValueArr = argsStr.split("&");  //多参数
        for (var i = 0; i < nameValueArr.length; i++) {
            var pos = nameValueArr[i].indexOf('=');
            if (pos == -1) continue; //如果没有找到就跳过
            var argName = nameValueArr[i].substring(0, pos); //提取name
            var argVal = nameValueArr[i].substring(pos + 1); //提取value
            args[argName] = unescape(argVal);
        }
        return args[paramName];
    }
}


function loaddata(type,id,name){
    //TODO 加载数据
    if($("#"+type).text()!=type){
        div='<div class="list '+type+'"><span id='+type+'>'+type+'</span></div>';
        $("#container").append(div);
        li = $("<li>").val(id).text(name);
        $("."+type).append(li);
    }else{
        li = $("<li>").val(id).text(name);
        $("."+type).append(li);
    }
}


function loadzonedata(type,id,name,container,tip){
    //TODO 加载省份、城市、地区数据
    if($("#"+type+tip).text()!=type){
        div='<div class="list '+type+tip+'"><span id='+type+tip+'>'+type+'</span></div>';
        $("#"+container).append(div);
        li = $("<li>").val(id).text(name);
        $("."+type+tip).append(li);
    }else{
        li = $("<li>").val(id).text(name);
        $("."+type+tip).append(li);
    }
}

function setCookie(cname,cvalue,min){
    var d = new Date();
    d.setTime(d.getTime()+(min*60*1000));  //加上时区标准时间
    var expires = "expires="+d.toGMTString();
    document.cookie = cname+"="+cvalue+"; "+expires;
}

function getCookie(cname){
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name)==0) { return c.substring(name.length,c.length); }
    }
    return "";
}

function checkCookie(cname){
    var cname=getCookie(cname);
    if(cname==''){
        alert('操作超时！请重新进入');
        window.location.href=mapurl('/userindex.html');
        return true;
    }else{
        return false;
    }
}

function getNowFormatDate(date) {
    //TODO 获取当前时间，格式YYYY-MM-DD
    // var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}

function diffDays(strDateStart,strDateEnd){
    var strSeparator = "-"; //日期分隔符
    var oDate1;
    var oDate2;
    var iDays;
    oDate1= strDateStart.split(strSeparator);
    oDate2= strDateEnd.split(strSeparator);
    var strDateS = new Date(oDate1[0], oDate1[1]-1, oDate1[2]);
    var strDateE = new Date(oDate2[0], oDate2[1]-1, oDate2[2]);
    iDays = parseInt(Math.ceil(strDateS - strDateE ) / 1000 / 60 / 60 /24);//把相差的毫秒数转换为天数
    return iDays ;
}


function Money(value, num) {
    //TODO 金额分段
    num = num > 0 && num <= 20 ? num : 2;
    value = parseFloat((value + "").replace(/[^\d\.-]/g, "")).toFixed(num) + ""; //将金额转成比如 123.45的字符串
    var valueArr = value.split(".")[0].split("") //将字符串的数变成数组
    var valueFloat = value.split(".")[1]; // 取到 小数点后的值
    var valueString = "";
    for (var i = 0; i < valueArr.length; i++) {
        valueString += valueArr[i] + ((i + 1) % 3 == 0 && (i + 1) != valueArr.length ? "," : ""); //循环 取数值并在每三位加个','
    }
    var money = valueString.split("").join("") + "." + valueFloat; //拼接上小数位
    // alert(money)
    return money
}


function digitUppercase(n) {
    //TODO 金额转大写
    var fraction = ['角', '分'];
    var digit = [
        '零', '壹', '贰', '叁', '肆',
        '伍', '陆', '柒', '捌', '玖'
    ];
    var unit = [
        ['元', '万', '亿'],
        ['', '拾', '佰', '仟']
    ];
    var head = n < 0 ? '欠' : '';
    n = Math.abs(n);
    var s = '';
    for (var i = 0; i < fraction.length; i++) {
        s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
    }
    s = s || '整';
    n = Math.floor(n);
    for (var i = 0; i < unit[0].length && n > 0; i++) {
        var p = '';
        for (var j = 0; j < unit[1].length && n > 0; j++) {
            p = digit[n % 10] + unit[1][j] + p;
            n = Math.floor(n / 10);
        }
        s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
    }
    return head + s.replace(/(零.)*零元/, '元')
        .replace(/(零.)+/g, '零')
        .replace(/^整$/, '零元整');
}